<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

</body>
<script>
    // 输入年月日,月份和日期输入错误都要重输入(月份在1-12之间,日期在1到当月最大天数之间).最后输出年月日.

    // 声明年月日
    let year = +prompt('请输入年：');
    let month = 0;
    let day = 0;

    // 天数数组
    let arr = [0, 31, year % 4 == 0 && year % 100 != 0 || year % 400 == 0 ? 29 : 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];

    // 如果输入月非 1~12月中，输入日非数字，或不是整数，或小于零，或超过当月最大天数，重新输入
    while (-1 == [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12].indexOf(month) || isNaN(day) || day != parseInt(day) || day < 0 || day > arr[month]) {
        month = +prompt('请输入月：');
        day = +prompt('请输入日：');
    }

    // 弹窗输出
    alert(`${year}年${month}月${day}日`);
</script>

</html>